package com.yanyeori.framework.security.config;

import com.yanyeori.framework.security.configprop.SecurityConfigProps;
import com.yanyeori.framework.security.database.InterfaceDao;
import com.yanyeori.framework.security.service.DefaultPermissionsService;
import com.yanyeori.framework.security.service.DefaultRateLimiterService;
import com.yanyeori.framework.security.service.PermissionsService;
import com.yanyeori.framework.security.service.RateLimiterService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenkuan 2021/3/12
 */
@Configuration
public class ServiceBeanConfig {

    @Bean
    @ConditionalOnMissingBean(PermissionsService.class)
    public PermissionsService defaultPermissionsService(SecurityConfigProps config, InterfaceDao interfaceDao) {
        return new DefaultPermissionsService(config, interfaceDao);
    }

    @Bean
    @ConditionalOnMissingBean(RateLimiterService.class)
    public RateLimiterService defaultRateLimiterService(SecurityConfigProps config, InterfaceDao interfaceDao) {
        return new DefaultRateLimiterService(config, interfaceDao);
    }
}
